package com.zch.starter.opentelemetry.code.mode.springboot.starter.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 使用@ConfigurationProperties 的好处是
 * 1 在业务项目中可以提示配置项 也可以跳转到配置项代码中
 * 2 将spring 上下文环境里的变量映射到这个java bean 的属性中
 *
 */
@ConfigurationProperties(prefix = "otel")
@Data
public class ZchOpentelemetryProperties {
    private Autoconfig autoconfig = new Autoconfig();
    private Exporter exporter = new Exporter();
    private Service service = new Service();
    private Traces traces = new Traces();
    private Metrics metrics = new Metrics();
    private Logs logs = new Logs();

    @Data
    public static class Autoconfig {
        /**
         * 是否启用 OpenTelemetry 自动配置
         * 默认值: true
         */
        private boolean enabled = true;
    }

    @Data
    public static class Exporter {
        /**
         * Collector 的服务端地址
         * 默认值: http://localhost:4318
         */
        private String endpoint = "http://localhost:4318";
    }

    @Data
    public static class Service {
        /**
         * 服务名称，支持 ${spring.application.name} 占位符
         */
        private String name = "${spring.application.name}";
    }

    @Data
    public static class Traces {
        /**
         * Traces 导出器类型
         * 默认值: otlp
         */
        private String exporter = "otlp";

        /**
         * Traces 采样器类型
         * 默认值: parentbased_traceidratio
         */
        private String sampler = "parentbased_traceidratio";

        /**
         * 采样器参数配置
         */
        private SamplerConfig samplerConfig = new SamplerConfig();

        @Data
        public static class SamplerConfig {
            /**
             * 采样率参数 (0~1, 1表示100%)
             * 默认值: 1
             */
            private double arg = 1;
        }
    }

    @Data
    public static class Metrics {
        /**
         * Metrics 导出器类型
         * 默认值: none
         */
        private String exporter = "none";
    }

    @Data
    public static class Logs {
        /**
         * Logs 导出器类型
         * 默认值: none
         */
        private String exporter = "none";
    }
}
